package com.pxxy.yuyi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pxxy.yuyi.dao.NewsDao;
import com.pxxy.yuyi.entity.News;
import com.pxxy.yuyi.service.NewsService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA
 *
 * @Author : XuWen
 * @create 2021/6/21 11:11
 */
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao newsDao;

    @Override
    public PageInfo<News> selectNewsType(Integer ntype, Integer pageNum) {
        News news=new News();
        news.setNtype(ntype);
        PageHelper.startPage(pageNum,6);
      List<News> list =  newsDao.selectNewsType(news);
        return new PageInfo<News>(list);
    }

    @Override
    public News selectByNid(String nid) {
        return newsDao.selectByNid(nid);
    }

    @Override
    public Integer deleteById(Integer nid) {
        return newsDao.deleteById(nid);
    }

    @Override
    public Integer addNews(News news) {
        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss a");// a为am/pm的标记
        Date date = new Date();// 获取当前时间
        System.out.println("当前时间-->"+date);

        news.setNtime(date);
        System.out.println("新闻----"+news);
        return newsDao.insertNews(news);
    }
}
